﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using MvcLibrary.Repository;
using System.IO;
using WebVideo.Areas.Admin.Models;

namespace WebVideo.Areas.Admin.Controllers
{
    public class TypeNewsController : Controller
    {
        //
        // GET: /Admin/TypeNews/

        public ActionResult Index()
        {
           

          return View(TypeNewsModel.LayDuLieu ());
        }
        #region "Insert"
        public ActionResult Insert()
        {
            TypeNewsModel tnew = new TypeNewsModel();
            return View(tnew);


        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Insert(TypeNewsModel  Mtnew)
        {

            try
            {
                if (ModelState.IsValid)
                {
                    TypeNewsModel.Insert(Mtnew);
                    return RedirectToAction("Index", "TypeNews");
                }
            }
            catch
            {

                return RedirectToAction("Index", "Error", new { errorMsg = "Lỗi SQL hosting / server" });
            }
            return View(Mtnew);
        }
        #endregion //insert


        #region "Edit"
        public ActionResult Edit(int IdTypeNews)
        {
           

            return View(TypeNewsModel.LayModel (IdTypeNews));

        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Edit(TypeNewsModel Mtnew)
        {

            try
            {
                if (ModelState.IsValid)
                {
                    TypeNewsModel.Edit (Mtnew);
                    return RedirectToAction("Index", "TypeNews");
                }
            }
            catch
            {

                return RedirectToAction("Index", "Error", new { errorMsg = "Lỗi SQL hosting / server" });
            }
            return View(Mtnew);
        }
        #endregion //Edit

        #region "Delete"

        public string Delete(int Id)
        {
            try
            {
                TypeNewsModel.Delete(Id);
                return "ok";

            }
            catch
            {
                return "error";

            }

        }

        #endregion //Delete
    }
}
